package com.all.play.myapplication.ui;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.all.play.myapplication.R;
import com.all.play.myapplication.bean.MainModelBean;
import com.all.play.myapplication.presenter.MainPresenter;
import com.all.play.myapplication.view.MainView;

public class MainActivity extends AppCompatActivity implements MainView{

    private TextView textView;
    private ProgressBar progressBar;
    private MainPresenter mainPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initview();
    }

    private void initview() {
        textView = (TextView) findViewById(R.id.tv);
        progressBar = (ProgressBar) findViewById(R.id.pb);
        mainPresenter = new MainPresenter(this);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mainPresenter.loadData();
            }
        },3000);
    }

    @Override
    protected void onDestroy() {
        mainPresenter.dittachView();
        super.onDestroy();
    }

    @Override
    public void show(MainModelBean mainModelBean) {
        String showData = getResources().getString(R.string.city) + mainModelBean.getCity()
                + getResources().getString(R.string.wd) + mainModelBean.getWd()
                + getResources().getString(R.string.ws) + mainModelBean.getWs()
                + getResources().getString(R.string.time) + mainModelBean.getTime();
        textView.setText(showData);
    }

    @Override
    public void showProgress() {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        progressBar.setVisibility(View.GONE);
    }
}
